class Player {
  constructor(options) {
    if (typeof options !== 'object') {
      return;
    }
    this.el = typeof options.el === 'object' ? options.el : document.querySelector(options.el)
    this.playUrl = options.url
    this.flvObj = options.flvObj
    this.flvPlayer = null
    this.mediaInfo = null
  }

  init() {
    if (this.flvObj.isSupported()) {
      this.flvPlayer = this.flvObj.createPlayer({
        type: 'flv',
        isLive: true,
        url: this.playUrl
      })
      this.flvPlayer.attachMediaElement(this.el);
      this.flvPlayer.load()
    }
  }

  play() {
    this.flvPlayer.play()
  }

  pause() {
    this.flvPlayer.pause()
  }

  destroy() {
    this.flvPlayer.pause();
    this.flvPlayer.unload();
    this.flvPlayer.detachMediaElement();
    this.flvPlayer.destroy();
    this.flvPlayer = null;
  }
}

export default Player